#coding=utf-8

require "aio/core"

class Aio::Module::Cmd::H3C::DisplayDeviceManuinfo < Aio::Module::Cmd::H3C
  include Aio::Module

  def initialize
    super({
      :cmd_full			=> "display device manuinfo",
      :cmd_short		=> "dis dev m",
      :author				=> "Elin",
      :description	=> "This is H3C Command# display device manuinfo",
      :ranking			=> Ranking_1,
      :platform			=> "all",
    })
  end

  def parse
    context = self.context.dup
    inv_info = {}
    useful[:inventory] = inv_info

    context.readline_range_loop(/:/, /VENDOR_NAME/) do |cont|
      slot_info = {}
      name = ""
      pid  = ""

      cont.readline_match_block(/(?<name>[^:]+):/) do |block|
        name = block[:name]
      end
      cont.readline_match_block(/DEVICE_NAME : (?<pid>.*)/) do |block|
        pid = block[:pid]
      end
      cont.readline_match_block(/DEVICE_SERIAL_NUMBER : (?<sn>.*)/) do |block|
        sn = block[:sn]
        inv_info[sn.to_sym] = slot_info
        block.update(slot_info, :name, name)
        block.update(slot_info, :description, "H3C")
        block.update(slot_info, :pid, pid)
        block.update(slot_info, :sn)
      end
    end
  end
end
